﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using JumbotCms.Common;

namespace JumbotCms.WebFile.MTag
{
    public partial class _view_invite : JumbotCms.API.UserCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User_Load("", "html");
            string mtagid = Str2Str(q("mtagid"));
            if (q("act") != "save")
            {
                string PageStr = GetPageHtml("mtag_invite");
                //是不是群主
                if (IsMTagModerator(UserId, mtagid))
                {
                    doh.Reset();
                    doh.SqlCmd = "SELECT a.id as mtagid,a.Title as mtagname,a.Img as mtagImg,a.MemberTotal as mtagMemberTotal,a.Proclaim as mtagProclaim,b.id as mtagsortid,b.Title as mtagsortname FROM " +
                        " [jcms_normal_mtag] as a left join [jcms_normal_mtag_sort] as b" +
                        " on b.id=a.SortId " +
                        " WHERE a.id=" + mtagid;
                    DataTable dtMTag = doh.GetDataTable();
                    for (int i = 0; i < dtMTag.Columns.Count; i++)
                    {
                        PageStr = PageStr.Replace("{$_" + dtMTag.Columns[i].ColumnName.ToLower() + "$}", dtMTag.Rows[0][i].ToString());
                    }
                    Response.Write(PageStr);
                    dtMTag.Clear();
                }
                else
                {
                    Response.Write("权限不足");
                    Response.End();
                }
            }
            else
            {
                if (!CheckFormUrl())
                    Response.End();
                doh.Reset();
                doh.ConditionExpress = "id=@id and UserId=" + UserId;
                doh.AddConditionParameter("@id", mtagid);
                doh.AddFieldItem("Img", f("txtImg"));
                doh.AddFieldItem("Proclaim", GetCutString(Jumbot.Common.Strings.HtmlEncode(f("txtProclaim")), 100));
                doh.AddFieldItem("JoinPower", f("ddlJoinPower"));
                doh.AddFieldItem("ViewPower", f("ddlViewPower"));
                doh.AddFieldItem("CloseApply", f("rblCloseApply"));
                if (doh.Update("jcms_normal_mtag") == 1)
                    Response.Write("JumbotCms.Alert('修改成功', '1', \"window.location='" + site.Dir + "mtag/view/index.aspx?mtagid=" + mtagid + "';\");");
                else
                    Response.Write("JumbotCms.Alert('提交有误', '0');");
            }
        }
    }
}
